package etxt2db.corpus;

import java.text.ParseException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;



public class IgnoreTagsTextBaseLoader extends MyTextBaseLoader{
	protected String labelLine(String line,StringBuffer docBuffer,String docId,
			List<CharSpan> spanList) throws ParseException{
		// stack of open tags

		// Create the matcher to find any XML marked up tags
		Pattern markupPattern=Pattern.compile(convertEscapeCharactersOutside(beginTagString) + "/?([^ " + convertEscapeCharactersInside(beginTagString) + convertEscapeCharactersInside(endTagString) + "]+)( [^" + convertEscapeCharactersInside(beginTagString) + convertEscapeCharactersInside(endTagString) + "]+)?" + convertEscapeCharactersOutside(endTagString));
		Matcher matcher=markupPattern.matcher(line);

		int currentChar=0;
		while(matcher.find()){
			docBuffer.append(line.substring(currentChar,matcher.start()));
			currentChar=matcher.end();
		}
		// append stuff from end of last tag to end of line into the buffer
		docBuffer.append(line.substring(currentChar,line.length()));
		docBuffer.append("\n");

		return docBuffer.toString();
	}
}
